package org.jaronsource.framework.core.service;

import java.io.Serializable;
import java.util.List;

import org.jaronsource.framework.core.dao.support.Criteria;
import org.jaronsource.framework.core.dao.support.IEntity;
import org.jaronsource.framework.core.dao.support.Page;
import org.jaronsource.framework.core.dao.support.PageRequest;
import org.springframework.transaction.annotation.Transactional;

@Transactional ( readOnly = true)
public abstract class SearchFormSupportGenericService<T extends IEntity<I>, I extends Serializable> extends GenericService<T, I> implements ISearchFormSupportGenericService<T, I> {

	@Override
	public List<T> find( SearchForm searchForm ) {
		Criteria criteria = parseForm( searchForm );
		return getDao().find( criteria );
	}

	@Override
	public Page<T> findPage( SearchForm searchForm ) {

		PageRequest pageRequest = searchForm.getPageRequest();

		Criteria criteria = parseForm( searchForm );

		return getDao().findPage( pageRequest, criteria );
	}

	protected Criteria parseForm( SearchForm searchForm ) {
		return SearchFormUtils.parseForm( searchForm );
	}

	
}
